require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsCrossArenaBattleHandler ={};
local this = RedDotsCrossArenaBattleHandler

function RedDotsCrossArenaBattleHandler.init()
    CloseEvent(Config.EventType.Fresh_Cross_Arena,this.update)
    ListenEvent(Config.EventType.Fresh_Cross_Arena,this.update)
    CloseEvent(Config.EventType.refreshDefFormation, this.update)
    ListenEvent(Config.EventType.refreshDefFormation, this.update)
    return this
end


--参数 无
function RedDotsCrossArenaBattleHandler.getFlag(...)

    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.CrossArena, false) then
        local crosArenaBaseoInfo = logicMgr.ArenaManager.getCrossBaseInfo()
        if crosArenaBaseoInfo ~= nil and crosArenaBaseoInfo.freeTimes > crosArenaBaseoInfo.times and (crosArenaBaseoInfo.endTime - Config.serverTime) > 0 then
            return Config.RedDotsFlagState.Needful
        end
        if logicMgr.FormationManager.checkDefFormationRedDotByType(EnumConst.FormationType.CrossArenaDef) then
            return Config.RedDotsFlagState.Needful
        end
    end
    return Config.RedDotsFlagState.None
end


function RedDotsCrossArenaBattleHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.CrossArenaBattle)
end